package documentooborot.display;

import java.io.File;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Map;

import documentooborot.display.ResponseWriter;

import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;

public class FileTemplateResponseWriter implements ResponseWriter {

	private Configuration cfg;
	private String templateName;

	public String getTemplateName() {
		return templateName;
	}

	public void setTemplateName(String templateName) {
		this.templateName = templateName;
	}

	@Override
	public String write(Map fetchedData) {
		Writer out = new OutputStreamWriter(System.out);
		try {
			cfg = new Configuration();
			cfg.setDirectoryForTemplateLoading(
			        new File("war/WEB-INF/"));
			cfg.setObjectWrapper(new DefaultObjectWrapper());
			Template temp = cfg.getTemplate(templateName);
			
			temp.process(fetchedData, out);
		} catch (Exception e) {}
		return out.toString();
	}

}
